package createmodel

import "sync"

/**
 * @File: singleton.go
 * @Author: SunShineBoy
 * @Author: SunShineBoy@163.com
 * @Date: 2024/12/5 14:45
 * @Project: GoProject
 * @IDE: GoLand
 * @Desc: 单例模式
**/

// Singleton 定义个结构体
type Singleton struct {
	Value string
}

// 定义变量
var (
	// 局部变量指针
	instance *Singleton
	Once     sync.Once
)

// GetInstance 实例化
func GetInstance() *Singleton {
	Once.Do(func() {
		instance = &Singleton{
			Value: "Singleton Value",
		}
	})
	return instance
}
